<?php
/**
 * Created by PhpStorm.
 * User: 12133
 * Date: 2024/4/12
 * Time: 14:11
 */

namespace app\controller\api;
use app\model\Message AS model;

class Buy extends Base
{
    public function list(){
        $list = model::where('user_id',$this->userInfo->id)
            ->order('create_time DESC')
            ->select();
        return $this->msg($list);
    }

    public function info($id){
        $info = model::find($id);
        return $this->msg($info);
    }

    public function save(){
        $id = input('id');
        $title = input('title');
        $name = input('name');
        $mobile = input('mobile');
        $info = input('info');
        $caption = input('caption');
        if (empty($id)) {
            model::create([
                'user_id' => $this->userInfo->id,
                'title' => $title,
                'name' => $name,
                'mobile' => $mobile,
                'info' => $info,
                'caption' => $caption
            ]);
        }else{
            $info = model::find($id);
            $info->save([
                'title' => $title,
                'name' => $name,
                'mobile' => $mobile,
                'info' => $info,
                'caption' => $caption
            ]);
        }
        return $this->msg();
    }
}